package com.hucheng.activity.entity;

import com.hucheng.activity.dto.LuckPrizeDetailsDTO;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;

import java.sql.Timestamp;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-07-10
 * @Description: 持久层数据
 **/
@Data
public class LuckPrizeDetailsDO {

    private Integer luckPrizeDetailsId;
    private Integer userId;
    private Integer luckPrizeConfigId;
    private String prizeName;
    private Integer isDel;
    private Timestamp dateCreated;
    private Timestamp dateUpdated;

    public static LuckPrizeDetailsDO buildLuckPrizeDetailsDO(final LuckPrizeDetailsDTO luckPrizeDetailsDTO) {
        if (luckPrizeDetailsDTO != null) {
            LuckPrizeDetailsDO luckPrizeDetailsDO = new LuckPrizeDetailsDO();
            Timestamp currentTime = new Timestamp(System.currentTimeMillis());
            if (StringUtils.isNotEmpty(luckPrizeDetailsDTO.getLuckPrizeDetailsId() + "")) {
                luckPrizeDetailsDO.setLuckPrizeDetailsId(luckPrizeDetailsDTO.getLuckPrizeDetailsId());
                luckPrizeDetailsDO.setDateCreated(luckPrizeDetailsDTO.getDateCreate());
            } else {
                luckPrizeDetailsDO.setDateUpdated(currentTime);
            }
            luckPrizeDetailsDO.setUserId(luckPrizeDetailsDTO.getUserId());
            luckPrizeDetailsDO.setLuckPrizeConfigId(luckPrizeDetailsDTO.getLuckPrizeConfigId());
            luckPrizeDetailsDO.setPrizeName(luckPrizeDetailsDTO.getPrizeName());
            luckPrizeDetailsDO.setIsDel(luckPrizeDetailsDTO.getIsDel());
            return luckPrizeDetailsDO;
        }
        return null;
    }
}
